package cn.kgc.projectmanagement.controller;

import cn.kgc.projectmanagement.pojo.ProjectInfo;
import cn.kgc.projectmanagement.service.ProjectInfoService;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;

@Controller
public class ProjectInfoController {
    @Resource
    ProjectInfoService service;

    @GetMapping("/go/index")
    public String goindex(){
        return "index";
    }
    @PostMapping("/pro/list")
    @ResponseBody
    public PageInfo<ProjectInfo> ProjectList(@RequestParam(value = "status",required = false,defaultValue ="0") Integer status,
                                             @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
                                             @RequestParam(value = "pageSize",required = false,defaultValue = "3")Integer pageSize){
        PageInfo<ProjectInfo> pageInfo=service.projectlist(status, pageNum, pageSize);
        return pageInfo;
    }
    @PostMapping("/pro/by/id")
    @ResponseBody
    public ProjectInfo getByid(Integer id){
        ProjectInfo projectInfo=service.getProject(id);
        projectInfo.setEnddate(new Date());
        return projectInfo;
    }

    @GetMapping("/pro/save")
    @ResponseBody
    public ProjectInfo getsage(ProjectInfo projectInfo){
        int result=service.getUpdate(projectInfo);
        if(result>0){
            return projectInfo;
        }else{
            return null;
        }
    }

}
